Repository navigation
fix(release): authenticate source catalog reads with the read-only job token - #69
Conversation
…b token The credential-free source job lists this repository's releases through api.github.com in two steps: version planning (crate_prepare.py pending) and asset preparation (crate_prepare.py prepare). crate_release.get() adds a token only when GH_READ_TOKEN is set, so both steps shared the hosted runner address's anonymous quota. Main's release failed twice on 2026-11-23 with "public request failed" in the planning step. Give both steps the job's GITHUB_TOKEN as GH_READ_TOKEN. The workflow is contents: read and the package job has no permissions override, so the token is read-only. Preparation already strips it before Cargo packaging and verification. The crate release policy check now requires exactly those two steps to carry the token, the package job to have no permissions block, and the workflow to keep contents: read. Re-anchor the reviewed release.yml digest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
…token check A YAML blank line does not end a block mapping, so the substring test let "contents: read", a blank line and further scopes such as id-token: write pass as "exactly contents: read". Read every entry of the single top-level permissions block instead. Also count the credential, not only the variable name: the package job may mention github.token only in the two catalog-reading steps and may not reference secrets, so a renamed variable, a secrets alias or a YAML anchor cannot carry the token to another step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Delta review of the source read-token check found three cheap defense-in-depth gaps behind the reviewed release.yml digest: - Split the top-level permissions block with splitlines(), so a CR, NEL, U+2028 or U+2029 inside a comment cannot hide a further scope that YAML parsers read as its own line. - Count github.token case-insensitively and without whitespace over the workflow up to the attest job, so an anchor defined before the package job is counted; refuse any secrets reference in the job, and toJSON(github) or github[...] before the attest job. - Refuse any "permissions" key spelling in the package job, including "permissions :" and a quoted key. Each clause has its own test case. release.yml is unchanged, so its digest stays anchored. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Self-review: #69 at 4ba3972Intent brief: give the What was reviewed
Findings and outcomes
Validation at 4ba3972
|
On main, "Prepare every immutable source and crate asset" runs tools/package-release.sh, which calls crate_prepare.py prepare, then known(), then catalog(). That makes the same anonymous api.github.com release listing as the plan step, about 20 minutes later on the same runner. Give that step the read-only job token too, matching atrinik/protocol#69. package-release.sh runs cargo metadata, cargo build --release, syft and other tools directly, so it moves the token into an unexported shell variable before any command and passes it only to crate_prepare.py prepare. clean_environment() already strips it from that script's Cargo and verifier children. The contract test now: - pins the token to exactly the plan and preparation steps; - counts every spelling of github.token; - rejects secrets, github[...], toJSON(github) and GITHUB_ENV exports in the package job; - pins package-release.sh's scoping. A unit test pins get(): it sends GH_READ_TOKEN only to api.github.com, and release downloads stay anonymous. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Back to draft until the merge-readiness gate passes: scope GH_READ_TOKEN inside package-release.sh to crate_prepare.py only |
…e-release.sh The preparation step's GH_READ_TOKEN reached everything package-release.sh runs, including the historical-crate cargo package and the contract bundle tool; only crate_prepare.py's own children went through clean_environment(). README and AGENTS.md overclaimed that preparation strips it before Cargo. Copy the token into a non-exported holder (declare +x also drops an inherited export of that name), unset GH_READ_TOKEN before the first command, and pass it only to crate_prepare.py prepare. The crate release policy check now requires those lines and the token's single use, and the docs say where it goes. release.yml is unchanged, so its digest stays. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…environment Delta review of f3ed70f found checker sub-conditions no test pinned and asked for the crate preparation environment guarantee the docs rely on: - Add script subtests that only the holder count (holder exported on a later line), the use line (token moved to cargo package) and the GH_READ_TOKEN count (indirect expansion) catch. Drop the separate "scope present" test: without the scope lines the partition leaves the whole script before them, which the command check already rejects. - Port content-toolkit's AST test: every non-git subprocess in crate_prepare.py must run with env=clean_environment(). - Say that only the two steps get the token in their environment; the pinned checkout and setup actions also receive it as their default token input. Don't overclaim what declare +x guards against. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Self-review: #69 at 121efefIntent brief: give the What was reviewed
Findings and outcomes
Later rounds: f3ed70f and 121efef
Validation at 121efef
|
|
🎉 This PR is included in version 2.29.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
The Semantic Release
packagejob reads this repository's release list fromapi.github.comwithout a token, so on hosted runners it shares the runner address's anonymous rate limit. Main's release failed this way twice on 2026-11-23. This PR gives the two steps that read the release list the job's read-onlyGITHUB_TOKENasGH_READ_TOKEN, and makes the crate release policy check enforce that placement.Why
The step "Plan the actual source version without write credentials" runs
scripts/release/source-version.mjs, which callstools/crate_prepare.py pending. That callsknown(), thencrate_release.catalog(), thenapi()andget().get()sendsAuthorizationonly whenGH_READ_TOKENis set, and only tohttps://api.github.com/URLs. The plan step didn't set it, so the firstreleases?per_page=100&page=1request counted against the runner address's 60/hour anonymous limit. Run 45127716142 failed there withValueError: public request failed(traceback throughpending→known→catalog→api→get), and run 45169466426 failed the same way on its first attempt.The later step "Prepare every immutable source and crate asset" has the same exposure.
tools/package-release.shcallscrate_prepare.py prepare, which onmainalso callsknown()→catalog(), plusold_content()→api('releases/tags/…'). It runs 20+ minutes after planning, on the same runner and address. If only the plan step were authenticated, a runner whose anonymous quota is spent would get past planning and then fail in preparation. So both steps get the token.Change
.github/workflows/release.yml: addsGH_READ_TOKEN: ${{ github.token }}to the env of the plan step and the prepare step. No other step changes:contents: read, and thepackagejob has nopermissions:override, so this token is read-only;persist-credentials: false;cargo fetchandtools/validate.sh.tools/package-release.sh: before its first command, it copiesGH_READ_TOKENinto a non-exported holder (declare +x, which also drops an inherited export of that name) and unsets it. It passes the token only tocrate_prepare.py prepare, so no other tool the script runs inherits it.tools/check-crate-release-policy.py: newcheck_source_read_token(). It requires:exactly those two steps carry
GH_READ_TOKEN: ${{ github.token }}under their stepenv:;nothing else in the
packagejob mentionsGH_READ_TOKEN;up to the
attestjob,github.tokenappears exactly twice, counted case-insensitively and ignoring whitespace so that anchors defined before the job count too;nothing up to the
attestjob usestoJSON(githuborgithub[, and thepackagejob references nosecrets;the
packagejob has nopermissionskey in any spelling;the single top-level
permissions:block has exactly one entry,contents: read. The whole block is parsed, because a YAML blank line doesn't end it. Lines are split withsplitlines(), so a CR, NEL, U+2028 or U+2029 inside a comment can't hide a scope.package-release.shscopes the token before any command other thanset -euo pipefail, passes it asGH_READ_TOKEN=${catalog_read_token} python3 tools/crate_prepare.py prepare, and mentionsGH_READ_TOKENand the holder nowhere else.It runs before the digest-gated
id-token: writeexemption, so a future re-anchor can't silently drop the token, move it to another step or widen the job's permissions.tools/test_crate_release_policy.py: two new tests.test_source_catalog_reads_use_only_the_read_only_job_tokenrejects nineteen workflow mutations:GH_TOKENthere, aliased throughsecrets.GITHUB_TOKENorsecrets['GITHUB_TOKEN'], reused through a YAML anchor inside or before the job, writtengithub.TOKEN,toJSON(github)orgithub [ 'token' ];contents: write,permissions : write-allor a quoted"permissions"key;contents: write, extra scopes after a blank line or hidden behind a U+2028 in a comment, orread-all.test_release_script_passes_read_token_only_to_crate_preparationrejects ten script mutations:cargo package;cargo package(directly or through indirect expansion), to the contract bundle tool, or re-exported.tools/test_crate_release.py: newtest_preparation_subprocesses_other_than_git_drop_the_read_token, ported from content-toolkit. It requires every non-gitsubprocesscall incrate_prepare.pyto run withenv=clean_environment(), and it pins the call count at 4.README.md,AGENTS.md: the source-job descriptions now say which two steps get the read-only token in their environment, and why. The README also notes that the pinned checkout and setup actions receive it through their defaulttokeninput. "Credential-free read-only job" becomes "read-only job without write credentials".Where the token goes
In the plan step, the node process passes its environment to the
crate_prepare.py pendingchild.In the prepare step,
package-release.shunsets the token before its first command and passes it only tocrate_prepare.py prepare. Itscargo metadata, historical-cratecargo package, contract bundle tool,syftand version probes don't inherit it.crate_prepare.clean_environment()then strips it again beforecargo packageandverify-packages.sh;test_actions_source_ref_cannot_be_overridden_and_read_token_not_in_buildcovers that. The plan step runs no Cargo. This goes beyond the AGENTS.md rule, which bars only registry tokens, OIDC capabilities and GitHub write credentials from Cargo and build scripts.Reviewed workflow digest (OIDC fence)
release.ymlmay containid-token: write(itsattestjob) only while the file's SHA-256 equalsEXPECTED_SOURCE_WORKFLOW_SHA256. This PR moves that anchor fromf897401…ae94to818d658…4d29, as #58 and #68 did. That re-blesses the whole file around the OIDC fence, so here is why it is safe:release.ymlchange is five added lines in thepackagejob: oneenv:key, a two-line comment and twoGH_READ_TOKENentries.attestjob (the only one withid-token: writeandattestations: write) and the write-enabledreleasejob are unchanged. So are triggers, concurrency, every permission block and every action pin.packagejob's ownGITHUB_TOKEN, withcontents: readonly. It is neither a write credential nor an OIDC capability, and thepackagejob still cannot request an OIDC token.publish-crate.ymlandEXPECTED_PUBLICATION_WORKFLOW_SHA256are unchanged.Release consequence
atrinik-protocol 0.2.2 is already published. crates.io and its sparse index both list it, created at 2026-11-23T12:57:09Z. The re-run of 45169466426 produced immutable source release v2.28.0 at 4c79b72, whose
crate-release.jsonownsatrinik-protocol 0.2.2. It then dispatchedpublish-crate.ymlrun 45179019748, and both jobs succeeded.Merging this PR therefore publishes nothing to crates.io. Like every merge to
main, it triggers Semantic Release, which creates an ordinary source release (v2.29.0, a minor because every commit type onmainis minor). The Cargo version is unchanged and 0.2.2 is owned by v2.28.0, so that release carries no registry crate. That run is also the first to use the token in the plan and prepare steps.Validation
tools/check-crate-release-policy.pypasses at 121efef. The 64 Python policy, release, schema and admission tests pass (61 before, plus the three new ones). ShellCheck 0.11.0 is clean onpackage-release.sh.crate_prepare.pyreceives the exact value;test-release-policy.cjspasses.test-source-version.mjsandtest-git-auth.mjspass with the pinned workflow dependencies.test-git-auth.mjsalso asserts token placement around the publish step.GH_READ_TOKENline from the realrelease.ymlmakes the checker andtest_current_policy_is_reviewed_and_validfail with the new message, whether or not the digest is re-anchored to the mutated file;check_source_read_token()makes the new test fail;splitlines, thepermissionskey spelling, counting before the job, case-insensitive counting,secretswithout a dot,toJSON(githubandgithub[;unset GH_READ_TOKENfrom the realpackage-release.sh, or passing the token to itscargo package, fails the checker andtest_current_policy_is_reviewed_and_valid;crate_prepare.py, any of these fails the AST test: removingenv=from the Cargo call, giving the verifieros.environ.copy(), adding an unscopedcargosubprocess, or addingos.system.catalog()path with an Actionsgithub.tokenalready runs hourly incrate-release-reconcile.yml; its recent runs succeeded.git diff --checkis clean.tools/validate.shaggregate (CRATE_BASE_REVISION=4c79b72) passed at e261ac2 in a throwaway Rust 1.97.1 / Go 1.26.6 / jq 1.7.1 container and left no tree changes. It covered generation drift, buf breaking, Go/Rust tests, the release dry-run andatrinik-protocol-0.2.2.cratepackage verification. It passed again at 7cb9bb9, f3ed70f and 121efef. The f3ed70f run includesvalidate.sh's ownpackage-release.shruns (release dry-run and non-owning revision) with the scoped token.Protocol validationruns the full aggregate on the PR head.Out of scope
attestandreleasejobs.crate_release.get()still falls back to anonymous reads when no token is set. Localcrate_prepare.pyuse is unchanged.🤖 Generated with Claude Code